﻿using System;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using System.Text;
using KPIS.DBM;
using KPIS.GERP.GAMS.MODEL;

namespace KPIS.GERP.GAMS.DAL
{
    public class D_BGM_MAS_Source
    {
        DBManager dbManager = new DBManager(SystemInfo._DataProvider, ConfigurationSettings.AppSettings["ConnectionString"].ToString());
        ConvertNullable cn = new ConvertNullable();

        public DataTable GetList()
        {
            try
            {
                dbManager.CreateParameters(1);
                dbManager.AddParameters(0, "@RecordStatus", SystemInfo._ActiveRecordStatus);
                string sql = " select bgm_source_seq, bgm_source_name"
                           + " from bgm_mas_source m"
                           + " where record_status = @RecordStatus"
                           + " and bgm_source_seq not in (select upper_bgm_source_seq from bgm_mas_source where record_status = @RecordStatus and upper_bgm_source_seq is not null)"
                           + " order by bgm_source_seq";
                DataTable dt = new DataTable();
                dbManager.Open();
                dt = dbManager.ExecuteDataSet(CommandType.Text, sql).Tables[0];
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dbManager.Dispose();
            }
        }

        public string GetCurrentBgmYear()
        {
            try
            {
                dbManager.Open();
                string sql = "select bgm_sys_control_values"
                           + " from bgm_system_control"
                           + " where bgm_sys_control_name = 'bg_year'";
                DataTable dt = new DataTable();
                
                dt = dbManager.ExecuteDataSet(CommandType.Text, sql).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    return dt.Rows[0][0].ToString();
                }
                else
                {
                    return "";
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dbManager.Dispose();
            }
        }
    }
}
